﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AoYing_DeviceCollection.Tools.LogHelper
{
    public static class DbLogger
    {
        public static void LogWrite(string context)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(string.Concat(context));
            Logger.Instance().Write(sb.ToString(), LogLevel.AppInfo);
        }
        public static void LogException(Exception ex, string lastCommand = null)
        {
            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(lastCommand))
                sb.AppendLine(string.Concat("LastCommand:", lastCommand));

            if (ex.InnerException != null)
                ex = ex.InnerException;

            sb.AppendLine(string.Concat("异常信息: " + ex.Message));
            sb.AppendLine(string.Concat("错误源:" + ex.Source));
            sb.AppendLine(string.Concat("堆栈信息:\r\n" + ex.StackTrace));

            Logger.Instance().Write(sb.ToString(), LogLevel.AppInfo);
        }
    }
}
